###########################################################################################################################
#      URL 
#    vBulletin 3.0.7
# Attachment Upload by URL for vBulletin 3.0.7
# By: Dark Visor (Anthony Kanevsky, ankan925@optonline.net)
# Released: April 20, 2005
# http://www.nabdh-alm3ani.net
###########################################################################################################################

### What this hack does: ###
--------------------------------------------------------------------------------------------------------------------------
  :
  :
---------------------------------------------------------------------------------------------------------------------------

Let's Begin!

---------------------------------------------------------------------------------------------------------------------------
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$																				$$$
$$$		 									$$$
$$$																				$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
---------------------------------------------------------------------------------------------------------------------------

###########################################################################################################################
#  
# ./newattachment.php
###########################################################################################################################

---------------------------------------------------------------------------------------------------------------------------
    284
---------------------------------------------------------------------------------------------------------------------------

		foreach ($_FILES AS $upload => $attachment)

---------------------------------------------------------------------------------------------------------------------------
 
---------------------------------------------------------------------------------------------------------------------------

		if (is_array($_POST['attachmenturl']))
		{
			foreach ($_POST['attachmenturl'] AS $key => $url)
			{
				// attempt to fetch the filename from the url
				preg_match('/\/([A-z0-9]*)([\.]{1})([A-z0-9]{2,6})$/si', $url, $matches);
				$filename['original'] = str_replace("/", "", $matches[0]);

				// did we retrieve a valid filename?
				$validurl = iif(!empty($url) AND !empty($filename['original']), true, false);

				if (function_exists('curl_init') AND $validurl)
				{
					// cancel the file that might have been uploaded
					unset($_FILES["attachment$key"]);

					// attempt retrieveing the url
					$curl_handle=curl_init();
					curl_setopt($curl_handle,CURLOPT_URL,$url);
					curl_setopt($curl_handle,CURLOPT_TIMEOUT,15);
					curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,15);
					curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
					curl_setopt($curl_handle,CURLOPT_FAILONERROR,1);
					$data = curl_exec($curl_handle);
					curl_close($curl_handle);

					if (empty($data))
					{ // tsk tsk
						$error = construct_phrase($vbphrase['error_cannot_retrieve_url'], $url);
						$errors[] = array(
							'filename' => htmlspecialchars_uni($url),
							'error' => $error
						);
					}
					else
					{ // ok, let's save the file
						$tmp_name = 'vbupload' . substr(TIMENOW, -4);
						$filesize = strlen($data);
	
						// write file to temporary directory...
						if ($vboptions['safeupload'])
						{
							// ... in safe mode
							$filename['temp'] = $vboptions['tmppath'] . "/$tmp_name";
							$filenum = @fopen($filename['temp'], 'wb');
							@fwrite($filenum, $data);
							@fclose($filenum);
						}
						else
						{
							// ... in normal mode
							$filename['temp'] = tempnam(ini_get('upload_tmp_dir'), 'vbupload');
							$fp = @fopen($filename['temp'], 'wb');
							@fwrite($fp, $data);
							@fclose($fp);
						}

						$_FILES["attachment$key"]['name'] = $filename['original'];
						$_FILES["attachment$key"]['type'] = '';
						$_FILES["attachment$key"]['size'] = $filesize;
						$_FILES["attachment$key"]['tmp_name'] = $filename['temp'];
						$_FILES["attachment$key"]['error'] = 0;
						$_FILES["attachment$key"]['url_upload_by_curl'] = 1;
					}
				}
			}
		}

---------------------------------------------------------------------------------------------------------------------------
    524
---------------------------------------------------------------------------------------------------------------------------

		$attachinput .= "<input type=\"file\" class=\"bginput\" name=\"attachment$boxcount\" />\n";

---------------------------------------------------------------------------------------------------------------------------
 
---------------------------------------------------------------------------------------------------------------------------

		$attachinput .= "&nbsp;".$vbphrase['or_upload_by_url']."&nbsp;&nbsp;\n";
		$attachinput .= "<input type=\"text\" class=\"bginput\" name=\"attachmenturl[$boxcount]\" /><br />\n";

###########################################################################################################################
#  
# ./includes/functions_file.php
###########################################################################################################################

---------------------------------------------------------------------------------------------------------------------------
    266
---------------------------------------------------------------------------------------------------------------------------

	if (!is_uploaded_file($attachment))

---------------------------------------------------------------------------------------------------------------------------
 
---------------------------------------------------------------------------------------------------------------------------

	if (!is_uploaded_file($attachment) AND !$attachment['url_upload_by_curl'])

---------------------------------------------------------------------------------------------------------------------------
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$																				$$$
$$$			 										$$$
$$$																				$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
---------------------------------------------------------------------------------------------------------------------------

###########################################################################################################################
#  
# newattachment
###########################################################################################################################

---------------------------------------------------------------------------------------------------------------------------
 
---------------------------------------------------------------------------------------------------------------------------

if (elm.type == 'file')

---------------------------------------------------------------------------------------------------------------------------
 
---------------------------------------------------------------------------------------------------------------------------

if (elm.type == 'file') || (elm.type == 'text')

---------------------------------------------------------------------------------------------------------------------------
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$																				$$$
$$$			 											$$$
$$$																				$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
---------------------------------------------------------------------------------------------------------------------------

###########################################################################################################################
: or_upload_by_url
 : GLOBAL
###########################################################################################################################
: 
    URL

###########################################################################################################################
: error_cannot_retrieve_url
 : GLOBAL
###########################################################################################################################
: 
  (<b>{1}</b>)    url
.

###########################################################################################################################
# 
###########################################################################################################################